home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / OS2CL016.ZIP / PMSYS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-26  |  2.6 KB  |  153 lines

  1. /* 
  2.  
  3.  
  4.     pmsys.cpp (emx+gcc) 
  5.  
  6.     1995 Giovanni Iachello
  7.     This is freeware software. You can use or modify it as you wish,
  8.     provided that the part of code that I wrote remains freeware.
  9.     Freeware means that the source code must be available on request 
  10.     to anyone.
  11.     You must also include this notice in all files derived from this
  12.     file.
  13.  
  14.  
  15. */
  16. #include <stdlib.h>
  17.  
  18. #include "pmsys.h"
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21.  
  22. PMMessageQueue::PMMessageQueue()
  23. {
  24.     hmq=0;
  25. }
  26.  
  27. PMAnchorBlock::PMAnchorBlock()
  28. {
  29.     hab=0;
  30. }
  31.  
  32. PMAnchorBlock::~PMAnchorBlock()
  33. {
  34. }
  35.  
  36. void PMAnchorBlock::init(int flags)
  37. {
  38.     hab = WinInitialize(flags);
  39. }
  40.  
  41. void PMAnchorBlock::uninit(void)
  42. {
  43.     WinTerminate(hab);
  44. }
  45.  
  46.  
  47. PMApp::PMApp(PMAnchorBlock iab,PMMessageQueue imq,int iargc,char** iargv)
  48. {
  49.     ab=iab; 
  50.     mq=imq;
  51.     argc=iargc;
  52.     argv=iargv;
  53. }
  54.  
  55. void PMApp::quit(int )
  56. {
  57. }
  58.  
  59. void PMApp::run(void)
  60. {
  61.     QMSG qmsg;
  62.     while ( ab.getMsg( &qmsg ) ) 
  63.         ab.dispachMsg ( &qmsg );
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67.  
  68. PMThread::PMThread(void* iarg,int istacksize)
  69. {
  70.     arg=iarg;
  71.     stacksize=istacksize;
  72.     id=_beginthread(threadstart,NULL,stacksize,(void*)this);
  73. }
  74.  
  75. PMThread::~PMThread()
  76. {
  77. }
  78.  
  79. void threadstart(void* arg)
  80. {
  81.     PMThread* pmt=(PMThread*)arg;
  82.     pmt->threadStore(NULL);        // annulla il puntatore
  83.  
  84.     pmt->main(pmt->arg);
  85.  
  86.     delete pmt->threadStore();     // elimina la zona di memoria del thread
  87.     delete pmt;
  88.     _endthread();
  89. }
  90.  
  91. void PMThread::threadStore(void *p)
  92. {
  93.     (*_threadstore())=p;    
  94. }
  95.  
  96. void* PMThread::threadStore()
  97. {
  98.     return *_threadstore();
  99. }
  100.  
  101. void PMThread::main(void* )
  102. {
  103. }
  104.  
  105. PMWindowThread::PMWindowThread(void* iarg,int istacksize,int iflags) : 
  106.     PMThread(iarg,istacksize), PMAnchorBlock() 
  107. {
  108.     flags=iflags;
  109.     init(flags);
  110. }
  111.  
  112. PMWindowThread::~PMWindowThread()
  113. {
  114. }
  115.  
  116. void PMWindowThread::main(void* )
  117. {
  118. }
  119.  
  120. /////////////////////////////////////////////////////////////////////////////
  121.  
  122. PMEventSemaphore::PMEventSemaphore(ULONG iulAttr,BOOL32 fState)
  123. {
  124.     ulAttr=iulAttr;
  125.     pszName=NULL;
  126.     ulCount=0;
  127.     rc=DosCreateEventSem(NULL,&hev,ulAttr,fState);
  128. }
  129.  
  130. PMEventSemaphore::PMEventSemaphore(PCSZ ipszName,ULONG iulAttr,BOOL32 fState)
  131. {
  132.     ulAttr=iulAttr;
  133.     pszName=ipszName;
  134.     ulCount=0;
  135.     rc=DosCreateEventSem(pszName,&hev,ulAttr,fState);
  136. }
  137.  
  138. // open semaphore
  139. PMEventSemaphore::PMEventSemaphore(PCSZ ipszName, PHEV phev)
  140. {
  141.     pszName=ipszName;
  142.     hev=*phev;
  143.     ulCount=0;
  144.     rc=DosOpenEventSem(pszName,&hev);
  145.     *phev=hev;
  146. }
  147. // close semaphore
  148. PMEventSemaphore::~PMEventSemaphore()
  149. {
  150.     rc=DosCloseEventSem(hev);
  151. }
  152.  
  153.